package es.maria;

import javax.servlet.*;

public final class ContextListener implements ServletContextListener {
    public void contextInitialized (ServletContextEvent servletContextEvent) {
        ServletContext servletContext = servletContextEvent.getServletContext ();
        try {
            LibrosBD LibrosBD = new LibrosBD ();
            servletContext.setAttribute ("BaseDatos", LibrosBD);
        }
        catch (Exception e) {
            servletContext.log ("No se pudo crear el atributo BaseDatos: " + e.getMessage ());
        }
    }

    public void contextDestroyed (ServletContextEvent servletContextEvent) {
        ServletContext servletContext = servletContextEvent.getServletContext ();
        LibrosBD LibrosBD = (LibrosBD) servletContext.getAttribute ("BaseDatos");
        LibrosBD.close ();
        servletContext.removeAttribute ("BaseDatos");
    }
}
